package com.origin.onlinesys.service.modules.interviewsys.impl;

import com.origin.onlinesys.common.services.BaseService;
import com.origin.onlinesys.domain.modules.interviewsys.Zone;
import com.origin.onlinesys.persistence.modules.interviewsys.ZoneMapper;
import com.origin.onlinesys.service.modules.interviewsys.IZoneService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Administrator on 2015/1/21 0021.
 * 校区
 */
@Service
public class ZoneServiceImpl extends BaseService<Zone> implements IZoneService{
    /**
     * 插入新数据
     * @param zone 校区对象
     * @return
     */
    public Zone insertZone(Zone zone){
        String id = this.checkHave(zone.getName());
        zone.setState("1");
        if(id == null){
            this.save(zone);
        }else{
            zone.setId(id);
            this.updateZone(zone);
        }
        return zone;
    }

    /**
     * 根据Id删除校区
     * @param id
     * @return
     */
    public int deleteZone(String id){
        Zone zone = new Zone();
        zone.setId(id);
        zone.setState("2");
        return this.update(zone);
    }

    /**
     * 修改校区
     * @param zone 校区对象
     * @return
     */
    public int updateZone(Zone zone){
        return this.update(zone);
    }
    /**
     * 查询所有
     * @return
     */
    public List<Zone> selectAllZone(){
        return this.queryAll();
    }

    /**
     * 根据校区状态查询校区数据
     * @param state
     * @return
     */
    public List<Zone> selectByState(String state){
        Zone zone = new Zone();
        zone.setState(state);
        return this.queryByWhere(zone);
    }
    public String checkHave(String name) {
        return ((ZoneMapper)mapper).checkHave(name);
    }
}
